﻿using System;
using System.Data;
using System.Configuration;
using System.Web;
using System.Web.Security;
using System.Web.UI;
using System.Web.UI.WebControls;
using System.Web.UI.WebControls.WebParts;
using System.Web.UI.HtmlControls;

/// <summary>
/// shareCode 的摘要说明
/// </summary>
public class shareCode
{
	public shareCode()
	{
		//
		// TODO: 在此处添加构造函数逻辑
		//
	}
    public string  getBigTypeBySmallType(string tID)
    { 
        EntityOprHelper helper = new EntityOprHelper();
        T_PRODUCT_SMALLTYPE _bType = helper.GetEntityByWhere<T_PRODUCT_SMALLTYPE>(" where PID='" + tID + "'");

        return _bType.PRODUCT_BIGTYPEID;
    }
    public string getTypeByBigType(string tID)
    {
        EntityOprHelper helper = new EntityOprHelper();
        T_PRODUCT_BIGTYPE _bType = helper.GetEntityByWhere<T_PRODUCT_BIGTYPE>(" where PID='" + tID + "'");

        return _bType.TYPEID;
    }

    public static string upFileToServer()
    {
        System.Web.HttpFileCollection files = System.Web.HttpContext.Current.Request.Files;
        String path = ConfigurationSettings.AppSettings["ImagesPath"]; //+ "Images/BookImages/";  //设置服务器上传的路径，即文件上传的位置
        for (int i = 0; i < files.Count; i++)
        {
            bool bIs = false;
            HttpPostedFile postfiles = files[i];
            //Bitmap outputfile = null;
            string fileName = System.IO.Path.GetFileName(postfiles.FileName);
            String fileExtension = System.IO.Path.GetExtension(postfiles.FileName).ToLower();
            String[] allowedExtensions = { ".gif", ".jpg", ".png", ".jpeg" };
            for (int nCount = 0; nCount < allowedExtensions.Length; nCount++)
            {
                if (fileExtension == allowedExtensions[nCount])
                {
                    bIs = true;
                }
            }
            if (bIs)
            {
                try
                {
                    string strName = path + fileName;
                    postfiles.SaveAs(strName);
                    string AppendPath = ConfigurationSettings.AppSettings["AppendPath"];
                    string outPath = AppendPath + fileName;
                    return outPath;
                }
                catch (Exception exp)
                {
                    throw exp;
                }
            }
            else
            {
                //lblErrorMessage.Text = "不能接受这种文件类型。";
                //ScriptManager.RegisterClientScriptBlock(this, this.GetType(), "", "alert('不能接受这种文件类型!')", true);

            }
        }
        return "";
    }


}
